package pdm.traj.conf;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class TrajConf {
	public static final String PDM_PART_PLAN = "PDM_PART_PLAN";
	public static final String DUMMY_IMPORT_ENTRY_PER_SEC = "DUMMY_IMPORT_ENTRY_PER_SEC";
	public static final String UPDATE_BUSY_BITMAP_SIZE = "UPDATE_BUSY_BITMAP_SIZE";
	public static final String UPDATE_TRAJ_CYCLE = "UPDATE_TRAJ_CYCLE";
	public static final String UPDATE_CALC_THRESHOLD = "UPDATE_CALC_THRESHOLD";
	public static final String UPDATE_BUSY_CHECK_CYCLE = "UPDATE_BUSY_CHECK_CYCLE";
	public static final String QUERY_TASK_CHECK_READY_CYCLE = "QUERY_TASK_CHECK_READY_CYCLE";
	private String confPath = "classpath:/settings.properties";
    private Resource resource;
	private Properties props;
	
	private static TrajConf instance = new TrajConf();
	
	public static TrajConf getInstance() {
		return instance;
	}
	
	private TrajConf() {}
	
	public String getProperty(String key) {
		return props.getProperty(key);
	}
	
	public int getIntProperty(String key) {
		return Integer.parseInt(props.getProperty(key));
	}
	
	public double getDoubleProperty(String key) {
		return Double.parseDouble(props.getProperty(key));
	}
	
	public long getLongProperty(String key) {
		return Long.parseLong(props.getProperty(key));
	}
	
	public void init() {
        props = new Properties();
		InputStream fis;
		try {
            resource = new ClassPathResource(confPath);
			fis = resource.getInputStream();
			props.load(fis);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String getConfPath() {
		return confPath;
	}

	public void setConfPath(String confPath) {
		this.confPath = confPath;
	}
}
